From 5095e87bb7cf0736e9afcc63665bdec7c51d00b6 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 16 Apr 2020 12:09:54 -0400 Subject: [PATCH] testsuite: Add some checks for focus states This is some opportunistic checking in a test that is really about focus chains, but better than nothing. --- testsuite/gtk/test-focus-chain.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/testsuite/gtk/test-focus-chain.c b/testsuite/gtk/test-focus-chain.c index 53fab0d5a3..5419dbc2ae 100644 --- a/testsuite/gtk/test-focus-chain.c +++ b/testsuite/gtk/test-focus-chain.c @@ -86,6 +86,34 @@ done: return diff; } +static void +check_focus_states (GtkWidget *focus_widget) +{ + GtkStateFlags state; + GtkWidget *parent; + + if (focus_widget == NULL) + return; + + /* Check that we set :focus and :focus-within on the focus_widget, + * and :focus-within on its ancestors + */ + + state = gtk_widget_get_state_flags (focus_widget); + g_assert_true ((state & (GTK_STATE_FLAG_FOCUSED|GTK_STATE_FLAG_FOCUS_WITHIN)) == + (GTK_STATE_FLAG_FOCUSED|GTK_STATE_FLAG_FOCUS_WITHIN)); + + parent = gtk_widget_get_parent (focus_widget); + while (parent) + { + state = gtk_widget_get_state_flags (parent); + g_assert_true ((state & GTK_STATE_FLAG_FOCUS_WITHIN) == GTK_STATE_FLAG_FOCUS_WITHIN); + g_assert_true ((state & GTK_STATE_FLAG_FOCUSED) == 0); + + parent = gtk_widget_get_parent (parent); + } +} + static char * generate_focus_chain (GtkWidget *window, GtkDirectionType dir) @@ -109,6 +137,8 @@ generate_focus_chain (GtkWidget *window, focus = gtk_window_get_focus (GTK_WINDOW (window)); + check_focus_states (focus); + if (focus) { /* ui files can't put a name on the embedded text, -- 2.30.2